// user.js 封装api接口的, 登录接口, 修改个人信息, 获取个人信息, 退出.....
// 封装接口 需要 axios  地址 参数
// 导入store
// import store from '@/store'
// 1.导入axios实例
import http from '@/utils/request'
// 2. 封装函数发送请求
export const reqLogin = (mobile, code) => {
  // 一定return 将这个promise对象返回
  return http({
    method: 'POST',
    url: 'v1_0/authorizations',
    data: {
      mobile,
      code
    }
  })
}

// 获取个人信息接口
export const reqGetUserInfo = () => {
  // const token = store.state.user.tokenInfo.token
  return http({
    method: 'GET',
    url: 'v1_0/user/profile'
    // headers: {
    //   // Authorization: 'Bearer eyJ0eXAiOiJKV1QiLcJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MTQzMjk1NjAsInVzZXJfaWQiOjEzMTk5OTI5Njk3NzE2MTQyMDgsInJlZnJlc2giOmZhbHNlfQ.nhvUe1l1Ksa4bzrIEuYINEWQSKjCd5kUSqLeUKR9MQ0'
    //   Authorization: 'Bearer ' + token
    // }
  })
}

// 获取用户关注列表
export const reqGetUserFollowings = () => {
  // const token = store.state.user.tokenInfo.token
  return http({
    method: 'GET',
    url: 'v1_0/user/followings'
    // headers: {
    //   Authorization: 'Bearer ' + token
    // }
  })
}
// 关注
export const reqFollowUser = (target) => {
  return http({
    method: 'POST',
    url: 'v1_0/user/followings',
    data: {
      target // 被关注用户的id
    }
  })
}
// 取关
export const reqUnFollowUser = (target) => {
  return http({
    method: 'DELETE',
    url: 'v1_0/user/followings/' + target // 被取关用户的id
  })
}

// 获取新的token的请求
export const reqGetNewToken = (refresh_token) => {
  return http(
    {
      method: 'PUT',
      url: 'v1_0/authorizations',
      headers: {
        Authorization: 'Bearer ' + refresh_token
      }
    }
  )
}
/**
 * 获取用户个人信息 (用于个人中心页的渲染数据)
 */
export const reqGetMyUserInfo = () => {
  return http({
    method: 'GET',
    url: '/v1_0/user'
  })
}
// 编辑提交用户资料api
export const reqUpdateUserInfo = (obj) => {
  return http({
    method: 'PATCH',
    url: 'v1_0/user/profile',
    // get/delete params   post/put/patch/data
    data: obj
  })
}
// 修改头像
export const reqUpdatePhoto = (formData) => {
  return http({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data: formData
  })
}
